package com.example.sprintboot.controller;

import com.example.sprintboot.common.Result;
import com.example.sprintboot.entity.Employee;
import com.example.sprintboot.service.EmployeeService;
import jakarta.annotation.Resource;
import jakarta.websocket.server.PathParam;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/employee")
public class EmployeeController {

    @Resource
    private EmployeeService employeeService;

    @PostMapping("/login")
    public Result login(@RequestBody Employee employee) {
      Employee dbEmployee =  employeeService.login(employee);
        return Result.success(dbEmployee);
    }



      //  查所有数据
    @GetMapping("/selectAll")
    public Result selectAll(){
        List<Employee> list=employeeService.selectAll();
        return Result.success(list);
    }

    //    查单个数据
    @GetMapping("/selectById/{id}")
    public Result selectById(@PathVariable Integer id){
        Employee employee=employeeService.selectById(id);
        return Result.success(employee);
    }

    //    新增数据
    @PostMapping("/add")
    public Result add(@RequestBody Employee employee) {
        employeeService.add(employee);
        return Result.success();
    }

    //    更新数据
    @PutMapping("/update")
    public Result update(@RequestBody Employee employee) {
        employeeService.update(employee);
        return Result.success();
    }

    //    删除数据
    @DeleteMapping("/deleteById/{id}")
    public Result deleteById(@PathVariable Integer id) {
        employeeService.deleteById(id);
        return Result.success();
    }
}
